//
//  NoteReadViewController.m
//  SmileRead
//
//  Created by dllo on 15/8/31.
//  Copyright (c) 2015年 JIZ. All rights reserved.
//

#import "NoteReadViewController.h"
#import "Path.h"

@interface NoteReadViewController ()

@property (nonatomic, retain) UITextView *textView;
@property (nonatomic, retain) NSDictionary *dic;
@property (nonatomic, retain) UIImageView *myIamgeView;
@property (nonatomic, retain) UILabel *titleLabel;

@end

@implementation NoteReadViewController

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.dic = [NSDictionary dictionary];
    }
    return self;
}

- (void)dealloc
{
    [_titleLabel release];
    [_myIamgeView release];
    [_dic release];
    [_textView release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.automaticallyAdjustsScrollViewInsets = NO;
}

- (void)createSubView
{
    UIImageView *sun = [[UIImageView alloc] initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, 150 * heightFit)];
    sun.image = [UIImage imageWithContentsOfFile:[Path pathOfImageWithName:@"sun.png"]];
    [self.view addSubview:sun];
    [sun release];
    
    UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
    UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:blur];
    effectView.frame = CGRectMake(0, 0, self.view.frame.size.width, 150 * heightFit);
    [sun addSubview:effectView];
    [effectView release];
    
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10 * widthFit, 10 * heightFit, self.view.frame.size.width - 150 * widthFit, 130 * heightFit)];
    self.titleLabel.numberOfLines = 0;
    self.titleLabel.textColor = [UIColor whiteColor];
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    self.titleLabel.font = [UIFont systemFontOfSize:18];
    NSAttributedString *string = [[NSAttributedString alloc] initWithString:@"Our mind is a sponge, Our heart is a stream." attributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
    self.titleLabel.attributedText = string;
    [effectView.contentView addSubview:self.titleLabel];
    [_titleLabel release];
    
    if ([self.dic objectForKey:@"image"]) {
        self.myIamgeView = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.frame.size.width - 140 * widthFit,  64 + 10 * heightFit, 130 * widthFit, 130 * widthFit)];
        self.myIamgeView.image = [UIImage imageWithData:[self.dic objectForKey:@"image"]];
        self.myIamgeView.backgroundColor = [UIColor greenColor];
        [self.view addSubview:self.myIamgeView];
        [_myIamgeView release];
    }
    
    self.textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 64 + 150 * heightFit, self.view.frame.size.width, self.view.frame.size.height- 64 - 150 * heightFit)];
    self.textView.font = [UIFont systemFontOfSize:20];
    self.textView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.textView];
}

- (void)receiceWithDic:(NSDictionary *)dic
{
    self.dic = dic;
    [self createSubView];
    NSString *string = [NSString stringWithFormat:@"    %@", [self.dic objectForKey:@"note"]];
    self.textView.text = string;
    self.textView.selectable = NO;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
